Skip to content

Fix tensorboardyt v2 transforms API#3866

Open
saurabhkthakur wants to merge 2 commits intopytorch:mainfrom
saurabhkthakur:fix-tensorboardyt-v2-transforms
Open

Fix tensorboardyt v2 transforms API#3866
saurabhkthakur wants to merge 2 commits intopytorch:mainfrom
saurabhkthakur:fix-tensorboardyt-v2-transforms

Conversation

@saurabhkthakur
Copy link
Copy Markdown

@saurabhkthakur saurabhkthakur commented May 5, 2026

Fixes #3857

Description

Updated

  1. v2 transforms migration
  2. net.eval() / net.train()
  3. f-string updates
  4. stale comment removal
image

Checklist

  • The issue that is being fixed is referred in the description (see above "Fixes #ISSUE_NUMBER")
  • Only one issue is addressed in this pull request
  • Labels from the issue that this PR is fixing are added to this pull request
  • No unnecessary issues are included into this pull request.

cc @subramen

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented May 5, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/tutorials/3866

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 59c2dc4 with merge base 5efb99a (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@svekars
Copy link
Copy Markdown
Contributor

svekars commented May 5, 2026

@claude

@claude
Copy link
Copy Markdown

claude Bot commented May 5, 2026

Claude finished @svekars's task in 1m 26s —— View job


Review of PR #3866

  • Gather context and read changed files
  • Review changes against origin/main
  • Post review feedback

Overall this PR correctly migrates the two tutorial files to the torchvision v2 transforms API and makes several good modernization changes. A few items to address:

Issues

  1. Stale prose reference to v1 APIbeginner_source/introyt/trainingyt.py:60 still reads:

    We use ``torchvision.transforms.Normalize()`` to
    zero-center and normalize the distribution of the image tile content
    

    This should be updated to reference torchvision.transforms.v2 (or just v2.Normalize) to match the new code.

    Fix this →

  2. Missing torch.no_grad() in validation loop — In tensorboardyt_tutorial.py:215-221, the validation loop switches to net.eval() but does not wrap inference in torch.no_grad(). The companion file trainingyt.py:302 correctly uses with torch.no_grad():. This is a best practice that should be consistent across tutorials teaching the same pattern.

    Fix this →

  3. Inconsistent formatting in v2.Compose — In tensorboardyt_tutorial.py:79-82, the list items inside v2.Compose use the old indentation style (bracket on same line, items oddly aligned). In trainingyt.py:75-79, it's formatted more cleanly with items on their own lines and a trailing closing bracket. These two tutorials are closely related and should be consistent.

Minor / Nits

  • tensorboardyt_tutorial.py:210: f'Batch {i+1}' — the spacing around + is inconsistent with trainingyt.py:255 which uses f' batch {i + 1} loss: {last_loss}'. Consistent spacing around operators is preferred (i.e., i + 1).

What looks good

  • v2 transforms migration (ToImage() + ToDtype(torch.float32, scale=True) replacing ToTensor()) is correct.
  • net.eval() / net.train() replacing net.train(False) / net.train(True) is the idiomatic modern approach.
  • Removal of the stale TensorFlow/TensorBoard compatibility comment block is appropriate.
  • super().__init__() replacing super(Net, self).__init__() is correct Python 3 style.
  • f-string modernization is clean and consistent.

@sekyondaMeta
Copy link
Copy Markdown
Contributor

@saurabhkthakur good job on this, just a minor fix:

Stale prose reference to v1 API — beginner_source/introyt/trainingyt.py:60 still reads:

We use torchvision.transforms.Normalize() to
zero-center and normalize the distribution of the image tile content
This should be updated to reference torchvision.transforms.v2 (or just v2.Normalize) to match the new code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update Intro YouTube TensorBoard tutorial — v2 transforms, eval/train, stale comments

3 participants